package com.zxy.fmmall.controller;


import com.zxy.fmmall.entity.Product;
import com.zxy.fmmall.service.ProductCommentService;
import com.zxy.fmmall.service.ProductParamService;
import com.zxy.fmmall.service.ProductService;
import com.zxy.fmmall.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/product")
@CrossOrigin
@Api(value = "提供商品详情接口",tags = "商品管理")
public class ProductController {
    @Autowired
    private ProductService productService;

    @Autowired
    private ProductCommentService productCommentService;

    @Autowired
    private ProductParamService productParamService;

    @GetMapping("/detail-info/{pid}")
    @ApiOperation("查询商品基本信息")
    public ResultVo selectBaseProducts(@PathVariable String pid){
        return productService.selectBaseProducts(pid);
    }

    @GetMapping("/detail-params/{pid}")
    @ApiOperation("查询商品参数")
    public ResultVo getProductParamsById(@PathVariable String pid){
        return productService.getProductParamsById(pid);
    }

    @GetMapping("/detail-commonts/{pid}")
    @ApiOperation("查询商品评论")
    public ResultVo selectProductComment(@PathVariable("pid") String pid,int pageNum,int limit){
        return productCommentService.selectProductComment(pid,pageNum,limit);
    }

    @GetMapping("/detail-commontsStatistics/{pid}")
    @ApiOperation("商品评论统计")
    public ResultVo getProductComment(@PathVariable("pid") String pid){
        return productCommentService.getProductComment(pid);
    }

    @GetMapping("listByCid/{cid}")
    @ApiOperation("查询三级目录下的商品")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "int",name = "pageNum",value = "页码",required = true),
            @ApiImplicitParam(paramType="int",name = "limit",value = "每页记录数",required = true)
    })
    public ResultVo getProductsByCategoryId(@PathVariable("cid") int categoryId, int pageNum, int limit,String brand){
        return productService.getProductsByCategoryId(categoryId,pageNum,limit,brand);
    }

    @GetMapping("listByKeyword/{keyword}")
    @ApiOperation("模糊查询")
    public ResultVo getProductsByKeyword(@PathVariable("keyword") String keyword, int pageNum, int limit){
        return productService.getProductsByKeyword(keyword,pageNum,limit);
    }

    @GetMapping("/selectByBrand/{categoryId}")
    @ApiOperation("商品分类(商品类别查询商品分类)")
    public ResultVo selectByBrand(@PathVariable("categoryId") Integer categoryId){
        return productParamService.selectByBrand(categoryId);
    }

    @GetMapping("/selectBrandBykeyword/{keyword}")
    @ApiOperation("商品分类(商品类别查询商品分类)")
    public ResultVo selectBrandByKeyword(@PathVariable("keyword") String keyword){
        return productParamService.selectBrandByKeyword(keyword);
    }
}
